package 二叉树;

import java.util.ArrayList;
import java.util.List;

public class 中序遍历 {

    public List<Integer> inorderTraversal(TreeNode root){
        List<Integer> result = new ArrayList<>();
        in(root, result); // 123 321 22222 333333
        return result;
    }

    private void in(TreeNode current, List<Integer> result){
        if(current == null){
            return;
        }
        in(current.left, result);
        result.add(current.val);
        in(current.right, result);// 123
    }

    private static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

}
